import publicJS from "@/hook/public.js";
export default function (callBack = () => {}) {
	const {defaultImg} = publicJS();
	
	//左侧tabs配置类型
	const tabsList = [
		{name: '网站配置',value: 'web_config'},
		{name: '公司信息配置',value: 'company'},
		{name: '个性化页面配置',value: 'web_diy'},
		{name: 'seo配置',value: 'web_seo'},
		// {name: '邮件配置',value: 'email'},
	];
	
	//数据类型
	const data_type = [
		{label:'数据模板 json',value:'json'},
		{label:'文本框 input',value:'input'},
		{label:'多行文本框 textarea',value:'textarea'},
		{label:'纯图单个 img',value:'img'},
		{label:'单选 radio',value:'radio'},
		{label:'富文本 editor',value:'editor'},
	]

	//组件类型
	const sub_name = [
		{label:'轮播',value:'shopSwiper'},
		{label:'多图',value:'imgs'},
		{label:'底部菜单',value:'tabbarList'},
		{label:'页面标题',value:'pageTitle'},
		{label:'文本信息',value:'text'},
		{label:'友情链接',value:'friendlyLink'},
		{label:'图文信息',value:'imgTextMultiple'},
		{label:'多行文本',value:'textMultiple'},
	]
	
	//上传图片图片 给不同的组件图片字段赋值
	const imgSuccess = (res,pickImg,data) => {
		pickImg.show = false;
		
		switch(true){
		    case pickImg.name == 'iconPath':
				data.value[pickImg.valueIndex].iconPath = res.value
		        break;
		    case pickImg.name == 'selectedIconPath':
				data.value[pickImg.valueIndex].selectedIconPath = res.value
		        break;
			case pickImg.name == 'imgs':
				data.value[pickImg.valueIndex].img = res.value
			    break;
			case pickImg.name == 'img':
				data.value.img = res.value
			    break;
		    default:
				data.value = res.value;
		}
	}
	
	//给某个配置 新增一个配置
	const unshiftSub = (data)=>{
		console.log(data)
		let value = undefined;
		switch(data.sub_name){
			case 'shopSwiper':
				value = {show:'1',img: defaultImg}
				break;
			case 'imgTextMultiple':
				value = {show:'1',img: defaultImg}
				break;
			case 'imgs':
				value = {img: defaultImg}
				break;
			case 'textMultiple':
				value = {show:'1',text: ''}
				break;
			default:
				value = {show:'1'}
		}
		data.value.unshift(value)
	}

	//添加配置，判断数据类型 给默认值
	const addSubFilter = (conData)=>{
		let value = undefined;
		switch(conData.form.data_type){
			case 'json':
				let subName = conData.form.sub_name;
				conData.form.notes = 'arr';
				
				//判断组件类型 给组件默认值
				switch(conData.form.sub_name){
					case 'shopSwiper':
						value = [{show:'1',img: defaultImg}]
						break;
					case 'imgTextMultiple':
						value = [{show:'1',img: defaultImg}]
						break;
					case 'imgs':
						value = [{img: defaultImg}]
						break;
					case 'textMultiple':
						value = [{show:'1',text: ''}]
						break;
					default:
						value = [{show:'1'}]
				}
			    break;
				
			case 'radio':value = 0; break;
			
			case 'img':value = defaultImg; break;
				
			default:
				conData.form.sub_name = '';
				conData.form.notes = '';
				value = ''
		}
		return value;
	}
	return {
		unshiftSub,
		tabsList,
		data_type,
		sub_name,
		imgSuccess,
		addSubFilter
	}
}